package apps.sim.core;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public abstract class AHandler implements IHandler {
	protected static final String SEPARATOR = System.getProperty("file.separator");

	public IHandlerConfig getHandlerConfiguration() {
		return null;
	}

	public void setHandlerConfiguration(IHandlerConfig config) {
	}

	public String getContentType() {
		return "text/xml;charset=utf-8";
	}

	public String readInput(InputStream in) throws Exception {
		final StringBuilder builder = new StringBuilder();
		final InputStreamReader reader = new InputStreamReader(in);
		final BufferedReader bReader = new BufferedReader(reader);
		String str;
		while ((str = bReader.readLine()) != null) {
			builder.append(str);
			builder.append("\n");
		}
		return builder.toString();

	}

	protected byte[] asByteArray(File file) throws IOException {
		final BufferedReader br = new BufferedReader(new FileReader(file));
		StringBuilder builder = new StringBuilder();
		String line;
		while ((line = br.readLine()) != null) {
			builder.append(line);
		}
		br.close();
		return builder.toString().getBytes();
	}

}
